home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
ELECTRON
/
1085.ZIP
/
FIRPLOT.ARC
/
README.FIR
< prev
Wrap
Text File
|
1988-04-01
|
11KB
|
253 lines
Firplot is a program which calculates the filter coefficients for
Finite Impulse Response (FIR) digital filters. It will run on all
PC-type computers.
If you intend to use FIRPLOT for serious work, rather than with
the reduced capability of this version, use the order blank at the
end of this file. The advantage of having the full 128 stage
capability is shown by examples in this file.
Paul Selwa
61 East Tilden Dr.
Brownsburg, Indiana 46112
FIR FILTERS.
There are various types of digital filters. Of these the Finite
Impulse Response (FIR) filter is the most useful. It is
unconditionally stable and has guaranteed linear phase response.
It is resistant to the effects of noise and is the least sensitive
type of digital filter to the effects of the precision (length) of
the filter coefficients.
CONSTRUCTION OF FIR DIGITAL FILTERS.
An FIR filter consists of the following components, some of which
can exist in hardware or in software.
1. A low pass filter (LPF) to limit the bandwidth of the signal.
It is called an anti-alaising filter.
2. An analog-to-digital converter (ADC). It may need to be
preceded by a sample and hold circuit if its conversion time
is long.
3. A data memory which saves the digitized samples of the signal
which is being processed. Data is usually put into two's
complement form to be compatible with most multipliers.
4. A set of filter coefficients which are used to multiply the
data memory's samples. These are usually in two's complement
(2C) form.
5. An accumulator which contains the sum-of-product terms which
are generated by multiplying the data memory contents by the
filter coefficients.
6. A multiplier chip, or a processor with multiplying capability.
7. A digital to analog converter (DAC) to change the filter's
output to an analog signal.
8. A low pass filter to remove noise from the output. It is
called a reconstruction filter and passes the same frequency
components as does the anti-alaising filter.
ALAISING:
Any digital filter has a bandwidth limitation which is set by the
sampling rate of the input ADC which must be at least twice the
bandwidth of the anti-alaising filter. The folding frequency is
defined as exactly one-half of the sampling rate and is
theoretically the maximum frequency which the filter can handle
without alaising problems. When a signal is being sampled at a
given rate, the signal's components are duplicated above and below
each harmonic of the sampling frequency, just as they would appear
as sidebands from an AM transmitter operating at the sampling
frequency. If you have a sampling rate of 10000 Hz and a signal
of 1000 Hz you would get spurious outputs from the sampler at 9000
Hz, (10000- 1000 Hz), and at 11000 Hz, (10000+1000 Hz), in
addition to the baseband signal of 1000 Hz. If the input signal's
frequency was raised to 4999 Hz the sampler would produce sideband
components at 5001 Hz, at 14999 Hz as well as the 4999 Hz baseband
signal. Clearly, the crossover point between the baseband signal
and the lower sideband image of it will occur at one-half of the
sampling rate. Input signals of frequency greater than the
folding frequency will appear as aliases of lower frequency
signals.
FILTER COEFFICIENTS.
The stored data samples are all multiplied by the filter's
coefficients, (also called filter taps), one-for-one in between
the acquisition of each successive data sample. The product of
each of the multiply operations is accumulated and this sum-of-
products result is a data word which is the filter's output until
the next output value is calculated.
The program first calculates a coefficient set for a filter having
unity gain (0 dB). While these tap weights will produce a working
filter, the set of numbers may not use the full 8 or 16 bit
capability of the processor you are building unless your hardware
can handle floating point math. After finding the tap weights for
the 0 dB filter, the program finds the largest valued coefficient
and linearly scales all of them to gain the best use of fixed
point hardware's mathematical range. These results are printed in
decimal and in 2C hexadecimal notation which has been scaled for a
16 bit machine.
The value of a 2C tap from the program will be equal to:
-1*(sign bit) + (positive value of the remaining bits)
with the left-most remaining bit having a value of +0.5, the next
having a value of +0.25 and so on.
OPERATION OF AN FIR FILTER.
Suppose you need a length 5 FIR filter. To make for easy notation
I will refer to the data samples as D1-Dx, to the coefficients as
C(1)-C(5). and to the outputs as O1-Ox. After the fifth data
sample is taken, the first useable output sample is produced. The
outputs prior to then will be unpredictable and you may want to
mute the output until then.
O1 = D1*C(5) + D2*C(4) + D3*C(3) + D4*C(2) + D5*C(1)
The output value O1 is placed in the output DAC. Calculation is
then halted until the 6th data sample appears. It replaces the
first sample, and then the second output is calculated. In all
cases, the new data sample replaces the oldest stored data sample.
O2 = D2*C(5) + D3*C(4) + D4*C(3) + D5*C(2) + D6*C(1)
Output sample O2 is placed into the output DAC. Again the filter
waits for the next data sample (which replaces the second sample),
and then calculates the third output sample.
O3 = D3*C(5) + D4*C(4) + D5*C(3) + D6*C(2) + D7*C(1).
This process is continued, and the filter produces outputs at the
same rate as the incoming samples.
OUTPUT DATA PROCESSING:
The multiplication of two 16 bit 2C words produces a 32 bit
product in which two identical sign bits occur. You will take the
top 16 bits as your result after you perform a left shift of one
bit to remove the redundant sign bit that results from the
multiplication of two 2C numbers. Some multipliers will provide
this function automatically.
The 2C result may have to be changed back to simple binary code
for the output DAC. This is easily accomplished by inverting the
sign bit position of the sum-of-products. This will shift the 2C
number to a value between zero and the maximum value your data
variable can achieve.
USING FIRPLOT:
Start the program by entering its name without the "EXE" file
extension. The program will prompt you for a file-name so it can
store the filter's parameters on disk. This file holds all of
your entries and all program data outputs.
THE PROGRAM DOES NOT CHECK FOR AN EXISTING FILE OF THE SAME NAME.
USE CAUTION IN NAMING THE DISK FILE !!!!!!!!!
PROGRAM INPUTS:
The number of bands is the total of the passbands plus the
stopbands. A simple lowpass filter requires an entry of 2.
The filter length is an integer between 3 and 128 inclusive, but
the length parameter is restricted to a smaller number in this
shareware version of FIRPLOT.
The band edges can be entered as decimal fractions of the sampling
rate, or as frequency variables. For the former mode the numbers
represent fractions of the sampling rate which can be anything
your hardware can handle. If you enter band edges as real
frequency values, the program will prompt you for the actual
sampling rate. There are several checks provided as you enter
these parameters. For example, if you enter the passband and
stopband edges as fractions of the sampling rate, and you call for
a band edge greater than the folding frequency, which is 0.5, the
program will go back to the first band edge so you can enter them
again. Similarly, if you had chosen to enter the band edges in
terms of frequency and one of them is of a frequency greater than
the folding frequency, the program will back up to the start of
the routine. This feature allows for easy escape from an error in
band edge definition without going back to the start of the
program. In addition, if a valid band edge was entered out of
sequence the program also returns to the start of the band edge
entry routine.
You will enter parameters which define the bands as passbands or
as stopbands. In that way you define lowpass, highpass, bandpass
and notch filters.
The final parameter is the RELATIVE ripple in the bands. These
are basically Chebyshev filters, but this is not the dB value of
the ripple. It is the ratio of the ripple values in the filter's
bands. The actual ripple values are minimized by the program.
PROGRAM OUTPUTS:
The program starts computing the filter's taps after the relative
ripple values are chosen. The execution time is mainly
proportional to the filter's length. A 128 tap filter can easily
take 15-20 minutes on a computer without a co-processor. In
general, a co-processor will cut the time by 80%. Run time is not
linearly related to filter length. Short filters will run in
seconds. The program will automatically use a co-processor if
there is one in the system.
The first output list is the impulse response of the filter. It
is named that because if a single data sample with a value of 1
was fed into the filter, preceded and followed by zeros, the
"impulse response" would show outputs equal to the filter's
coefficients. The next list is a version of the impulse response,
which is scaled to force the maximum of the impulse response's
absolute values to fall as close as possible to "-1" if the
largest coefficient was negative, or to "+1-(one LSB of a 16 bit
binary 2C number)" if the largest absolute value was a positive
number. The gain change that this causes in the filter's output
level is printed at the top of the scaled impulse response
listing.
The accompanying two's complement hex listing is based on a 16 bit
fixed point hardware system. If you want to use a smaller operand
pick the number of bits you wish, starting with the MSB of the hex
number.
The next output data is a list of the filter's gain as a function
of frequency. Its resolution is in steps of 0.05*(sampling rate).
The filter's gain data is plotted and is stored on disk. First,
in a compressed form which fits on the CRT and provides you with a
quick look at the filter's response curve, and second, in 1 dB
resolution if you request that output. The 1 dB plot is optional
because it will also go to the disk well as to the CRT and really
eats up disk space. The detailed plot contains characters to
indicate the direction of amplitude changes since high order
filters have stopband nulls that are very close together.
PROBLEMS.
There are conditions you can ask for that the program cannot
handle. These are usually in terms of extremely sharp cutoff
requirements and will cause either a divide by zero error, or in a
failure to converge to a mathematical solution. The first type of
error will be flagged by your operating system, and the second by
the filter design program. There are no known problems in the
program, and it is based on a well proven algorithm.
EXAMPLES: